package com.ohos.connent.bizscenecloud.biz.modular.dp.utils;

/**
 * @Author MZQ
 * @Description
 * @Date 2025/6/3 10:08
 **/
public class Base36IncrementUtils {


    public static String incrementBase36(String value) {
        char[] digits = value.toCharArray();
        int len = digits.length;
        boolean carry = true;

        // 从字符串的最后一位开始向前遍历，进行进位处理
        for (int i = len - 1; i >= 0 && carry; i--) {
            if (carry) {
                carry = incrementChar(digits, i);
            }
        }

        // 如果最高位有进位，需要在最前面添加一个'1'
        if (carry) {
            char[] newDigits = new char[len + 1];
            newDigits[0] = '1';
            System.arraycopy(digits, 0, newDigits, 1, len);
            return new String(newDigits);
        } else {
            return new String(digits);
        }
    }

    private static boolean incrementChar(char[] digits, int index) {
        char currentChar = digits[index];
        char nextChar;
        if (currentChar >= '0' && currentChar < '9') {
            nextChar = (char) (currentChar + 1);
        } else if (currentChar >= 'A' && currentChar < 'Z') {
            nextChar = (char) (currentChar + 1);
        } else if (currentChar == '9') { // 对于'9'的处理，变为'A'并设置进位为true
            nextChar = 'A';
        } else if ( currentChar == 'Z'){ //
            nextChar = '1';
            digits[index] = nextChar;
            return true;
        } else {
            return false;
        }
        digits[index] = nextChar;
        return false; // 无进位发生
    }


    private static int counter = 0;
    private static final int MAX = 36 * 36 *36 *36 ; // 36进制两位数的最大值



}
